package Tracing;

import UI.View;
import prefuse.data.Table;

public class HistoryStack extends Table {
	
	public HistoryStack(){
		super();
		addColumn("variable", String.class);
		addColumn("expression", String.class);
		addColumn("state", State.class);
		addColumn("Estate", State.class);
		addColumn("Benvironment", EnvironmentStack.class);
		addColumn("Line", String.class);
	}
	
	public void push(String var, String exp, State state, State Estate, EnvironmentStack Benv, String line){
		this.addRow();
		int rowCount = this.getRowCount();
		this.setString(rowCount-1, "variable", var);
		this.setString(rowCount-1,"expression",exp);
		this.set(rowCount-1, "state", state);
		this.set(rowCount-1, "Estate", Estate);
		this.set(rowCount-1,"Benvironment",Benv);
		this.setString(rowCount-1,"Line",line);
	}
	
	public void pop(){
		this.removeRow(this.getRowCount()-1);
	}
	
	public String toString(){
		StringBuffer buf = new StringBuffer();
		for(int i = 0; i < this.getRowCount(); i++){
			/*buf.append(i + ": "+UI.Constants.zuokuohao+this.getString(i, "variable")+":="+
					this.getString(i, "expression")+", "+this.getString(i, "state")+ 
					UI.Constants.compare+this.getString(i, "Estate")+UI.Constants.youkuohao+"\n");
			*/
			buf.append(i + ": "+UI.Constants.zuokuohao+this.getString(i, "variable")+":="+
					this.getString(i, "expression")+", "+this.getString(i, "state")+ ", " + UI.Constants.benvironment + UI.Constants.youkuohao+"\n");
			buf.append("B-environment " + UI.Constants.benvironment+": "+this.getString(i, "Benvironment"));
			buf.append("\n---------------------------------------------------------\n");
			
		}
		
		return buf.toString();
	}
	
	public void print(){
		System.out.println("****************Trace stack " + UI.Constants.historyStack + "******************");
		System.out.println(this.toString());
	}
	
	public void print(View view){
		view.getProcessPanel().getTextArea().setText("****************Trace stack " + UI.Constants.historyStack + "******************\n"+this.toString());
		
	}

}
